<%@page pageEncoding="UTF-8" %>
<!doctype html>
<html lang="zh-cmn">
<head>
    <%@include file="/WEB-INF/jsp/comm/head.jsp"%>
</head>
<body>

    <div class="container">
        <div class="panel panel-default">
            <div class="panel-body">
                <form class="form-inline">
                    <div class="form-group">
                        <label>线路编号:&nbsp;&nbsp;</label>
                        <select name="lineCode" class="form-control">
                            <option value="">--请选择--</option>
                        </select>
                    </div>&nbsp;&nbsp;
                    <div class="form-group">
                        <label>线路状态:&nbsp;&nbsp;</label>
                        <select name="runningStatusName" class="form-control">
                            <option value="">--请选择--</option>
                            <option value="正常">正常</option>
                            <option value="检修中">检修中</option>
                        </select>
                    </div>&nbsp;&nbsp;
                    <button type="button" class="btn btn-info" onclick="mhcx()"><i class="glyphicon glyphicon-search"></i>&nbsp;查询线路</button>
                    <button type="button" class="btn btn-primary" onclick="addLine()"><i class="glyphicon glyphicon-plus-sign"></i>&nbsp;添加线路</button>
                    <button type="button" class="btn btn-danger" onclick="delLine()"><i class="glyphicon glyphicon-remove"></i>&nbsp;删除线路</button>
                </form>
            </div>
        </div>
        <table id="lineTb"
               data-toggle="table"
               data-url="${ctx}/line/mhSearch"
               data-striped="true"
               data-pagination="true"
               data-side-pagination="server"
               data-page-size="5"
               data-page-list="[5,10,15]"
               data-query-params="queryParams"
               data-toolbar="toolbar"
               data-detail-view="true"
               data-detail-formatter="searchDetailList"
               data-click-to-select="true">
            <thead>
            <tr>
                <th data-radio="true"></th>
                <th data-field="poleInfo.lineCode">线路编号</th>
                <th data-field="poleInfo.lineName">线路名称</th>
                <th data-field="xiao">起始杆号</th>
                <th data-field="da">终止杆号</th>
                <th data-field="towerBasenum">塔基数</th>
                <th data-field="runningStatusName">运行状态</th>
                <th data-field="isStart" data-formatter="fomStart">启用状态</th>
                <th data-events="events" data-formatter="fmtCz">操作</th>
            </tr>
            </thead>
        </table>
    </div>

    <div id="add">
        <form class="form-horizontal">
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">线路编号：</label>
                        <div class="col-md-7">
                            <input type="text" name="lineCode" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">线路名称：</label>
                        <div class="col-md-7">
                            <input type="text" name="lineName" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">线路长度：</label>
                        <div class="col-md-7">
                            <input type="text" name="lineLength" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">回路长度：</label>
                        <div class="col-md-7">
                            <input type="text" name="backLength" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">投运日期：</label>
                        <div class="col-md-7">
                            <input type="text" name="prodUctDate" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">电压等级：</label>
                        <div class="col-md-7">
                            <input type="text" name="voltageLevel" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">起始杆号：</label>
                        <div class="col-md-7">
                            <select name="startPolecodeA" class="form-control">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">终止杆号：</label>
                        <div class="col-md-7">
                            <select name="endPolecodeA" class="form-control">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">塔基数：</label>
                        <div class="col-md-7">
                            <input type="text" name="towerBasenum" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">备注：</label>
                        <div class="col-md-7">
                            <input type="text" name="common" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-4 control-label">是否启用：</label>
                <div class="col-md-5">
                    <label class="radio-inline">
                        <input type="radio" name="isStart" value="1" checked/>启用
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="isStart" value="0"/>不启用
                    </label>
                </div>
            </div>
        </form>
    </div>

    <div id="update">
        <form class="form-horizontal" method="post">
            <input type="hidden" name="id">
            <%--<div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">线路编号：</label>
                        <div class="col-md-7">
                            <input type="text" readonly="readonly"  name="lineCode" value="${lineCode}" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">线路名称：</label>
                        <div class="col-md-7">
                            <input type="text" readonly="readonly" name="lineName" value="${lineName}" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>--%>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">投运日期：</label>
                        <div class="col-md-7">
                            <input type="text" readonly="readonly" name="prodUctDate" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">回路长度：</label>
                        <div class="col-md-7">
                            <input type="text" name="backLength" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">线路长度：</label>
                        <div class="col-md-7">
                            <input type="text" name="lineLength" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">电压等级：</label>
                        <div class="col-md-7">
                            <input type="text" name="voltageLevel" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">起始杆号：</label>
                        <div class="col-md-7">
                            <select name="startPolecode" class="form-control">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">终止杆号：</label>
                        <div class="col-md-7">
                            <select name="endPolecode" class="form-control">
                                <option value="">--请选择--</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">塔基数：</label>
                        <div class="col-md-7">
                            <input type="text" name="towerBasenum" class="form-control"/>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <label class="col-md-5 control-label">备注：</label>
                        <div class="col-md-7">
                            <input type="text" name="common" class="form-control"/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-4 control-label">是否启用：</label>
                <div class="col-md-5">
                    <label class="radio-inline">
                        <input type="radio" name="isStart" value="1" checked/>启用
                    </label>
                    <label class="radio-inline">
                        <input type="radio" name="isStart" value="0"/>不启用
                    </label>
                </div>
            </div>
        </form>
    </div>

<%@include file="/WEB-INF/jsp/comm/foot.jsp"%>
<script src="/static/hcJs/lineJs.js"></script>
<script src="/static/js/setForm.js"></script>
<script>
    /**
     * 添加时起始杆号
     */
    $(function(){
        $.getJSON(ctx+"pole/startPole",function(arr){
            $(arr).each(function(){
                var $opt=$("<option/>");
                $opt.html(this.poleCode);
                $opt.val(this.poleCode);
                $opt.appendTo("[name=startPolecodeA]");
            });
        });
    });
    $(function(){
        $.getJSON(ctx+"pole/startPole",function(arr){
            $(arr).each(function(){
                var $opt=$("<option/>");
                $opt.html(this.poleCode);
                $opt.val(this.poleCode);
                $opt.appendTo("[name=endPolecodeA]");
            });
        });
    });

    /**
     * 修改
     */
    function fmtCz(value, row){
        var editStart = row["isStart"] == 1 ? '<button class="btn btn-primary editStart">停用</button>' : '<button class="btn btn-danger editStart">启用</button>'
        var update = '<button class="btn btn-default update">修改</button>';
        return editStart+update;
    }
    var events = {
        "click .editStart" : function(e,value,row){
            updateStart(row);
        },
        "click .update" : function(e, value, row){
            edit(row);
        }
    }
    /**
     * 修改状态
     * @param row
     */
    function updateStart(row){
        var userStatus;
        if(row["isStart"]==1){
            isStart=0;
        }else{
            isStart=1;
        }
        if(row["runningStatusName"]=="正常"){
            runningStatusName="检修中";
            runningStatus=2;
        }else{
            runningStatusName="正常";
            runningStatus=1;
        }
        $.post(ctx+"line/updateStart",{id:row["id"],lineCode:row["poleInfo"].lineCode,isStart:isStart,runningStatus:runningStatus,runningStatusName:runningStatusName},function(msg){
            toastr.success("信息提示",msg);
            $("#lineTb").bootstrapTable("refresh");
        })
    }
    $(function(){
        $.getJSON(ctx+"pole/searchAll",function(arr){
            $(arr).each(function(){
                var $opt=$("<option/>");
                $opt.html(this.poleCode);
                $opt.val(this.poleCode);
                $opt.appendTo("[name=startPolecode]");
            });
        });
    });
    $(function(){
        $.getJSON(ctx+"pole/searchAll",function(arr){
            $(arr).each(function(){
                var $opt=$("<option/>");
                $opt.html(this.poleCode);
                $opt.val(this.poleCode);
                $opt.appendTo("[name=endPolecode]");
            });
        });
    });
    /**
     * 修改线路
     */
    $(function(){
        $("#update").dialog({
            title:"修改线路",
            btnName:"确定",
            btnBind:function(){
                var param=$("#update form").serialize();
                $.post(ctx+"line/update",param,function(msg){
                    toastr.warning("信息提示",msg);
                    $("#update").dialog("close");
                    $("#lineTb").bootstrapTable("refresh");
                },'text');
            }
        });
    });
    function edit(row){
        $("#update form")[0].reset();
        console.info(row);

        $("#update").setForm(row);
        var row=$("#lineTb").bootstrapTable("getSelections");

        $("#update").dialog("open");
    }
</script>
</body>
</html>